package com.karl.leetcode.test.medium.run;

import com.karl.leetcode.test.medium.solution.AddTwoNumbersDefaultSolution;
import com.karl.leetcode.test.medium.solution.Solution;

import java.util.HashMap;
import java.util.Map;

/**
 * 两数加和:运行器
 *
 * @author 李克国
 * @version 1.0.0
 * @project leetcode-test
 * @date 2020/12/31 10:48
 * @description 两数加和:运行器
 */
public class AddTwoNumbersRunner implements SolutionRunner {

    private Map<String, Solution> solutionMap;

    public AddTwoNumbersRunner() {
        init();
    }

    public void init() {
        solutionMap = new HashMap<>(2);
        AddTwoNumbersDefaultSolution defaultSolution = new AddTwoNumbersDefaultSolution();
        solutionMap.put(defaultSolution.getSolutionInfo().getId(), defaultSolution);
    }

    @Override
    public void run(String solutionId) {
        Solution solution = solutionMap.get(solutionId);
        if (solution == null) {
            throw new RuntimeException("为找到指定的解决方案");
        }
        System.out.println("开始。。。");
        solution.run();
        System.out.println("结束。。。");
    }
}
